package br.ufla.pgcc.oomeasures.measures;

import org.eclipse.jdt.core.dom.CompilationUnit;

import br.ufla.pgcc.oomeasures.astvisitors.AttributeVisitor;

public class NumberOfAttributes extends Measure {
	private double value;
	
	public NumberOfAttributes() {
		super();
		value = 0d;
		addApplicableGranularity(Granularity.CLASS);
	}

	@Override
	public String getName() {
		return "Number of Attributes";
	}

	@Override
	public String getAcronym() {
		return "NOA";
	}

	@Override
	public String getDescription() {
		return "Return the number of public attributes of a class";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	/**
	 * Return the maximum value
	 * @return -1 if this measure doesn't have a maximum value (infinity value)
	 */
	@Override
	public double getMaxValue() {
		return -1;
	}

	/**
	 * Return the reference value
	 * @return -1 if this measure doesn't have a reference value 
	 */
	@Override
	public double getRefValue() {
		return 0;
	}

	@Override
	public <T> void measure(T unit) {
		
		// Now create the AST for the ICompilationUnits
		CompilationUnit parse = parse(unit);
		AttributeVisitor visitor = new AttributeVisitor();
		parse.accept(visitor);

		setCalculatedValue(visitor.getNumberOfAttributes());
	}

	@Override
	public double getCalculatedValue() {
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value;
	}

}
